import Vue from 'vue'
import Vuex from 'vuex'

import { userInfo, changeAvatar, modifyPic, guess } from "../api/api"

userInfo
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isLogin: true,
    userInfo: "",


    guess: "",

  },
  mutations: {
    changeLogin(state, payload) {
      state.isLogin = payload.isLogin
      state.userInfo = payload.userInfo

    },
  },

  actions: {
    checkLogin(context) {
      // 个人信息
      userInfo().then(res => {
        console.log(res);
        if (res.code == 0) {
          context.commit("changeLogin", { isLogin: false, userInfo: res.data })
        }
      })

    },
    checkAvatar() {
      changeAvatar().then((res) => {
        console.log(res);
        modifyPic().then((res) => {
          console.log(res);
          this.file = res.url;
        });
      });
    },
    getGuess() {
      guess().then(res => {
        console.log(res);
        this.guessList = res.newslist
      })
    }
  },
  modules: {
  }
})
